function subs(strs) {
  let str = strs.split('')
  let ans = []
  let path = ''
  process(str, 0, ans, path)
  console.log(ans)
}

function process(str, index, ans ,path) {
  if(index == str.length) {
    ans.push(path)
    return
  }
  let no = path
  process(str, index +1, ans , no)
  let yes = path + str[index]
  process(str, index +1, ans , yes)
}

subs('ab')